package com.lrs.java.dataStructure.stack_queue;

class Queue {

	private int nElems;
	private long[] queueArray;
	private int front;
	private int rear;

	public Queue(int capacity) {
		queueArray = new long[capacity];
		
		front = 0;
		rear = -1;
		nElems = 0;
	}

	public void insert(long elem) {
		if(rear == queueArray.length - 1) {
			rear = -1;
		}
		queueArray[++rear] = elem;
		nElems++;
	}

	public long remove() {
		long temp = queueArray[front++];
		if(front == queueArray.length) {
			front = 0;
		}
		nElems--;
		return  temp;
	}
	
	public long peekFront() {
		return queueArray[front];
	}
	
	public boolean isFull() {
		return nElems == queueArray.length;
	}

	public boolean isEmpty() {
		return nElems == 0;
	}
	
	public int size() {
		return nElems;
	}
	
}

class QueueApp {
	
	public static void main(String[] args) {
		Queue queue = new Queue(10);

		queue.insert(21);
		queue.insert(34);
		queue.insert(13);
		queue.insert(45);
		queue.insert(78);
		queue.insert(63);
		
		System.out.println("size: " + queue.size());
		
		while(!queue.isEmpty()) {
			long data = queue.remove();
			System.out.print(data + ", ");
		}
		
	}
	
}

